# -*- encoding:utf8 -*-
from attendance.datetimestub import datetime,datetime_orig

#sys.modules['django.utils.timezone']=sys.modules['datetime']
from django.test import TestCase
from datetime import date,datetime
from annual import yearspan,annual_left_this,annual_accum,annual_left_last
import annual
annual.timezone=datetime
from staff.models import StaffInfo
from attendance.tool_func import get_or_none
from attendance.convert import i2day
from attendance.models import AvaiLeave
from import_leave_data import dummy_weixin
from django.conf import settings
from import_leave_data import import_leaves

class AnnualTest(TestCase):
    def setUp(self):
        self.staff,createed=StaffInfo.objects.get_or_create(employee_id='AE1856',cn_name=u'何宇林',startjob_date='2014-01-04',on_board_date='2015-09-07')
        AvaiLeave.objects.get_or_create(staff=self.staff,category='annual_leave',span='20:00')
    def test_annual(self):
        datetime.set_now(datetime_orig.datetime(2016,5,30))
        self.assertEqual(i2day(annual_accum(self.staff)),'3.29')
        self.assertEqual(i2day(annual_left_this(self.staff)),'3.29')
        self.assertEqual(i2day(annual_left_last(self.staff)),'2.50')
    
    #def test_input_data(self):
        #with open(r'C:\Users\heyulin\Desktop\excel\leave_data_simple.xlsx', 'rb') as f:
            #data=f.read()
            
            #import_leaves(data)    
       
class FunTest(TestCase):
    def test_yearspan(self):
        self.assertEqual(yearspan(date(2015,10,1),date(2014,5,1)),1)
        self.assertEqual(yearspan(date(2015,1,1),date(2014,5,1)),0)
        self.assertEqual(yearspan(date(2015,5,1),date(2014,5,1)),0)
        self.assertEqual(yearspan(date(2015,5,2),date(2014,5,1)),1)
    
    def test_import_data(self):
        print('0000000-dummy ----------')
        print(settings.DUMMY_WEIXIN)
        dummy_weixin()
        print(settings.DUMMY_WEIXIN)
    
